//
//  HWInviateReceiveView.m
//  HWanGame
//
//  Created by 王昌健 on 2022/9/2.
//  Copyright © 2022 94Wan. All rights reserved.
//

#import "HWInviateReceiveView.h"
@interface HWInviateReceiveView()
/** bg */
@property (strong, nonatomic) UIView *bgView;
/** 标题 */
@property (strong, nonatomic) UILabel *titleLabel;
/** 按钮 */
@property (strong, nonatomic) UIButton *cancelButton;
@property(strong, nonatomic) UIButton *sureButton;
@property(strong, nonatomic) UITextField *textField;
@end
@implementation HWInviateReceiveView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initUI];
        
        [self initFrame];
        
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        
        [self initFrame];
    }
    return self;
}
#pragma mark - ---------- 创建UI ---------- -

- (void)initUI{
    self.backgroundColor = [UIColor clearColor];
    self.type = MMPopupTypeAlert;
    self.bgView = [[UIView alloc] init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.bgView.layer setCornerRadius:8.f];
    [self addSubview:self.bgView];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"发放奖励";
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.bgView addSubview:self.titleLabel];
    
    self.textField = [[UITextField alloc] init];
    self.textField.placeholder = @"请输入发放数额";
    self.textField.keyboardType = UIKeyboardTypeNumberPad;
    [self.bgView addSubview:self.textField];
    
    self.cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    self.cancelButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.cancelButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
    [self.cancelButton addTarget:self action:@selector(cancelButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.cancelButton];
    
    self.sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.sureButton setTitle:@"发放" forState:UIControlStateNormal];
    self.sureButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.sureButton setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
    [self.sureButton addTarget:self action:@selector(sureButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.sureButton];
    
    [self.textField becomeFirstResponder];
    
}
- (void)initFrame{
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(ScreenWidth);
        make.height.mas_equalTo(ScreenHeight);
    }];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.centerX.mas_equalTo(0);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
        make.height.mas_equalTo(30);
    }];
    
    
    [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(self.textField.mas_bottom).offset(20);
        make.right.mas_equalTo(self.bgView.mas_centerX);
        make.bottom.offset(-20);
    }];
    
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgView.mas_centerX);
        make.top.mas_equalTo(self.textField.mas_bottom).offset(20);
        make.right.mas_equalTo(0);
        make.bottom.offset(-20);
    }];
}

- (void)cancelButtonClick:(UIButton *)button{
    [self hide];
    [self resignFirstResponder];
}

- (void)sureButtonClick:(UIButton *)button {
    [self resignFirstResponder];
    if (self.textField.text.length > 0) {
        self.clickButton(self.textField.text);
    } else {
        [MBProgressHUD  showError:@"请填写正确的数值"];
    }

}
@end
